package com.example.main;

import com.example.main.PlayCards.State;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;


public class Coint extends View{
	
	int heightScreen;
	int widthScreen;
	
	int FontMoney = 30;
	int nDefaultMoney = 1000;
	
	int nMoneyX = 0;
	int nMoneyY = 0;
	
	int BetCoint = 0;
	public Coint(Context context) {
		super(context);
		DisplayMetrics metrics = context.getResources().getDisplayMetrics();
		widthScreen = metrics.widthPixels;
		heightScreen = metrics.heightPixels;
		
		if (widthScreen <=320){
			FontMoney = 20;
		}else if (widthScreen == 480){
			nMoneyX = 100;
			nMoneyY = 100;
		}

		Init();
		// TODO Auto-generated constructor stub
	}

	Bitmap[] bitCoins = new Bitmap[] {
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_1),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_5),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_10),
			BitmapFactory.decodeResource(getResources(), R.drawable.coin_20),

		};
	
	public void Init(){

	}

	public void DrawCoints(	Canvas c ){
		
		Paint paint = new Paint();
//		paint.setStyle(Style.FILL);
		paint.setTextSize(FontMoney);
		
	
		String Bet = "BET = ";
		Bet += String.valueOf(BetCoint); 

		paint.setColor(Color.WHITE);
		c.drawText(Bet, (widthScreen/2)-100, heightScreen/2, paint);
		
		for (int i = 0; i < bitCoins.length; i++){
			
			c.drawBitmap(bitCoins[i], 0, (heightScreen - bitCoins[0].getHeight())-bitCoins[i].getHeight()*i, null);
		}
		
		String Money = String.valueOf(nDefaultMoney);
		c.drawText(	"Money", widthScreen-nMoneyX, heightScreen-nMoneyX, paint);
		c.drawText(	Money, widthScreen-nMoneyX, heightScreen-(nMoneyX-FontMoney), paint);

	}
	
	
	public void Click (float nX, float nY){
		
		for (int i = 0; i < bitCoins.length; i++){
	    	if (nX >= 0 && nX <  bitCoins[0].getWidth()
	    			&& nY >= (heightScreen - bitCoins[0].getHeight())-bitCoins[i].getHeight()*i && 
	    			nY < ((heightScreen - bitCoins[0].getHeight())-bitCoins[i].getHeight()*i + bitCoins[0].getHeight())) {

	    		switch(i) {
	    		case 0:
	    			BetCoint+=1;
	    			nDefaultMoney -= 1;
	    			break;
	    		case 1:
	    			BetCoint+=5;
	    			nDefaultMoney -= 5;
	    			break;
	    		case 2:
	    			BetCoint+=10;
	    			nDefaultMoney -= 10;
	    			break;	    		
	    		case 3:
		    		BetCoint+=20;
		    		nDefaultMoney -= 20;
		    		break;
	    		}
	    	}
		}
		
	}
	
}
